const { messageList } = require('../../utils/api')
Page({
    data: {
        active: 0,
        prePageData: null,
        list: [],
        num: 1,
        type: null,
        hasMore: true,
        loadFlag: true
    },

    onLoad: function(options) {
        const data = JSON.parse(options.data)
      console.log(data,'data')
        const type = data.childList.length ? data.childList[0].id : data.id
        this.setData({
            prePageData: data,
            type
        })
        this.getData()
        wx.setNavigationBarTitle({
            title: data.title
        })
        wx.hideShareMenu()
    },
    getData() {
        wx.showNavigationBarLoading()
        wx.showLoading({
            title: '加载中...'
        })
        messageList({
            pageSize: 20,
            pageNumber: this.data.num,
            type: this.data.type
        }).then(res => {
            wx.hideNavigationBarLoading()
            wx.hideLoading()
            wx.stopPullDownRefresh()
            if (this.data.num == 1) {
                this.setData({
                    list: []
                })
            }
            console.log(res)
            this.setData({
                list: this.data.list.concat(res.list)
            })
        })
    },
    onChange(e) {
        let index = e.detail.index
        let id = this.data.prePageData.childList[index].id
        this.setLoadInfo(id)
    },
    setLoadInfo(type) {
        this.setData({
            list: [],
            num: 1,
            type: type
        })

        this.getData()
    },
    onReady: function() {},
    onShow: function() {},

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {},

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {},

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {
        this.setLoadInfo()
    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {},

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {}
})
